<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/8/23
 * Time: 10:57
 */

namespace app\weixin\controller;
use think\Db;
use think\Validate;
class JoinCityPartner extends Base
{
   public function index(){
       $this->assign('title','申请合伙人');
       return view();
   }
    public function add(){
        //接收form表单
        $post = $_POST;
        $rule = [
            'name'                 => 'require|unique:php_partner,name',
            'phone'                 => 'require|[1][3-9][0-9]{9}',
            'tname'                 => 'require',
            'address'                 => 'require',
        ];
        $msg = [
            'name.require'         => '请输入姓名',
            'name.unique'         => '你已申请，请耐心等待',
            'phone.require'         => '请输入联系电话',
            'phone'         => '请输入正确的联系电话',
            'tname.require'         => '请输入推荐人姓名',
            'address.require'         => '请输入地址',

        ];
        $validate = new Validate($rule, $msg);
        if(!$validate->check($post))
        {
            $this->error($validate->getError());
        }
        $data = Db::table('php_partner')->insert($post);
        if($data){
            return $this->ajaxReturn("申请成功",1);
        }else{
            return $this->ajaxReturn("申请失败",0);
        }
    }
}